<div class="row">
	<div class="col-xs-12">
		<div class="box">
			<div class="box-header">
				<h3 class="box-title">粉丝管理</h3>
				<div class="box-tools pull-right">
				</div>
			</div>
			<div class="box-body">
                <div class="form-group">
                    <div class="col-md-3">
                        <div class="input-group date ">
                            <div class="input-group-addon">
                                <i class="fa fa-calendar"></i>
                            </div>
                            <input type="text" class="form-control pull-right" id="searchDate" placeholder="根据关注时间搜索...">
                        </div>
                    </div>
                    <div class="col-md-3">
                        <div class="input-group">
                            <span class="input-group-addon"><i class="fa fa-search"></i></span>
                            <input type="text" class="form-control" id="nickname" placeholder="根据昵称搜索...">
                        </div>
                    </div>
                    <div class="col-md-3">
                        <button type="button" onclick="tbReload();" class="btn btn-primary">搜索</button>
                    </div>
                </div>
                <div class="col-md-12">
				<table id="tb_tab" class="table table-bordered table-striped">
					<thead>
						<tr>
							<tr>
								<th>openid</th>
								<th>昵称</th>
                                <th>头像</th>
                            	<th>性别</th>
								<th>省</th>
                            	<th>市</th>
								<th>关注时间</th>
                                <th>关注状态</th>
                                <th>分销商</th>
							</tr>
						</tr>
					</thead>
				</table>
				</div>
			</div>
		</div>
	</div>
</div>


<script type="text/javascript">
var ajax_tab;

$(function() {

    $('#searchDate').datepicker({
        language: 'zh-CN',
        format: 'yyyy-mm-dd',
        autoclose: true,
        todayHighlight: true
    });

	//初始化表格
    ajax_tab = $('#tb_tab').DataTable({
        "dom":'itflp',
        "processing":true,
        "searching":false,
        "bInfo":false,
        "bServerSide":true,
        "paging":true,
        "bSort":false,
		"language":{"url":"plugins/datatables/language.json"},
		"ajax":{"url":"/admin/wx/fans/page","type":"post"},
		"columns":[
			{"data":"openid"},
            {"data":"nickname"},
            {"data":"headimgurl"},
            {"data":"sex"},
            {"data":"province"},
            {"data":"city"},
            {"data":"subscribeTime"},
            {"data":"subscribe"},
            {"data":null}
			],
		"columnDefs":[
            {
                targets: 2,
                data: null,
                render: function (data) {
                    if (data.trim() != ''){
                        return '<img src="'+data+'" width="25px" height="auto">';
                    }
                    return '';
                }
            },
            {
                targets: 3,
                data: null,
                render: function (data) {
					if (data == 1 ){
						return "男";
					}
                    if (data == 0 ){
                        return "女";
                    }
					return "未知";
                }
            },
            {
                targets: -2,
                data: null,
                render: function (data) {
                    if (data){
                        return '关注';
                    }
                    return '取消关注';
                }
            },
            {
                "targets" : -1,
                "data" : null,
                "render" : function(data) {
                var btn = '<a class="btn btn-xs btn-info"  target="modal"  modal="lg" href="/admin/wx/fans/distlist?lv=1&id='+ data.id+'">一级</a>&nbsp;'
                         +'<a class="btn btn-xs btn-warning"  target="modal"  modal="lg" href="/admin/wx/fans/distlist?lv=2&id='+ data.id+'">二级</a>&nbsp;'
                         +'<a class="btn btn-xs btn-success"  target="modal"  modal="lg" href="/admin/wx/fans/distlist?lv=3&id='+ data.id+'">三级</a>&nbsp;'
                    return btn;
                }
            }
             ]
	}).on('xhr.dt', function ( e, settings, data ,xhr) {
        dataTableMsg(data,xhr);
    } );
});



function tbReload(){
    var searchDate = $("#searchDate").val();
    var nickname = $("#nickname").val();
    var param = {
        "searchDate" : searchDate,
        "nickname" : nickname
    };
    ajax_tab.settings()[0].ajax.data = param;
    ajax_tab.ajax.reload();
}


</script>